package es.luimoco.wishlist;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

class WishAdapter extends ArrayAdapter<Wish> {
 
    private ArrayList<Wish> items;
 
    public WishAdapter(Context context, int textViewResourceId, ArrayList<Wish> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.lista_item, null);
        }
        Wish wish = items.get(position);
        if (wish != null) {
        	ImageView IVwish_icon = (ImageView) v.findViewById(R.id.wish_icon);
            TextView TVwish_titulo = (TextView) v.findViewById(R.id.wish_titulo);
            TextView TVwish_observacion = (TextView) v.findViewById(R.id.wish_observacion);
            if (IVwish_icon != null){
            	IVwish_icon.setImageBitmap(wish.getWish_icon());
            }
            if (TVwish_titulo != null) {
                TVwish_titulo.setText(wish.getWish_titulo());
            }
            if (TVwish_observacion != null) {
                TVwish_observacion.setText(wish.getWish_observacion());
            }
        }
        return v;
    }
}
